/**
 * 会员中心 云打印
 */
$(document).ready(function(e) {	
	$("#searchBeginTime").val(getDay());
	$("#searchEndTime").val(getDay());
	search(1);
})

/*初始化选项*/
function searchReset(){
	$("#searchBeginTime").val(getDay());
	$("#searchEndTime").val(getDay());
	$("#searchtype").val(-1);
	$("#searchPrintName").val('');
	$("#searchMemberName").val('');
}
function getDay(){
	var $time= new Date();
	$year = parseInt($time.getFullYear());
	$month = parseInt($time.getMonth())+1;
	$day = parseInt($time.getDate());
	if($month<10){
		$month ='0'+ $month;
	}
	if($day<10){
		$day ='0' + $day;
	}
	return $year +"-"+ $month +"-"+$day;	
}


function getSearchParameter(currentPage){
	try{
		var searchTitle= $("#searchTitle").val();	
		var btime = $("#searchBeginTime").val(),
			etime = $("#searchEndTime").val(),

			type	= $("#searchtype").val(),
			printname	= $("#searchPrintName").val(),
			membername	= $("#searchMemberName").val();

		//if(status==0) status=-1;
		if(!currentPage) currentPage=1;
		if(!printname) printname="";
		if(!membername) membername="";

		//requestJson ={"endTime":etime,"startTime":btime,"printerName":printname,"memberName":membername,"jobType":type,"pn":currentPage,"ps":(currentPage*10)};
		requestJson ={"currentPage":currentPage,"data":{"like":{"printerName":printname,"memberName":membername},"equals":{"startTime":btime,"endTime":etime,"spaceId":"","jobType":type,"clientId":""}}};
		return requestJson;
	}catch(e){
		console.log(e.messge);
	}
	return false;	
}

function search(currentPage){
	var memberToken = localStorage.getItem('memberToken');
	var requestJson = getSearchParameter(currentPage);
	if(requestJson == false){
		return false;
	}
	
	
	$.ajax({
        url: '/euc/print/myprint',
        data:JSON.stringify(requestJson),
       // data:'{"data":{"status":-1,"startTime":"2017-12-31","endTime":"2018-12-31","spaceId":0},"currentPage":1}',
        beforeSend: function(request) {
            request.setRequestHeader("token",memberToken );
        },
        dataType: 'JSON',
        async: true,
        contentType:'application/json;charset=utf-8',
        type: 'POST',
        success: function (result, textStatus, response) {
        	if(result.status === -2){
        		gotoLogin();
        	}
        	//alert(JSON.stringify(result));
        	pageBean = result.data;
        	$("#userTable").empty();	
        	
        	$.each(result.data.list,function(i,data){
        		       		

        		var bgcolor= localStorage.getItem('trcolor');
        		if(i % 2 == 0){
        			bgcolor = '';
        		}
        		var html = '<tr '+ bgcolor +'>';
        		html += '<td>' +  $.trim(data.jobInTime)  + '</td>';
        		html += '<td>' +  $.trim(data.spaceName) + '</td>';
        		html += '<td>' +  $.trim(data.printerName) + '</td>';
        		html += '<td>' +  $.trim(data.documentName) + '</td>';
        		html += '<td>' +  $.trim(data.jobType) + '</td>';
        		html += '<td>' +  $.trim(data.memberName) + '</td>';
        		html += '<td>' +  $.trim(data.totalCost) + '</td>';
  
        		html += '</tr>';
	        	$("#userTable").append(html);
	        	$("#totalRow").html(pageBean.totalRow+'&nbsp;');
	        	$("#currentPage").html(pageBean.currentPage+'&nbsp;');
	        	$("#pageSize").html(pageBean.pageSize+'&nbsp;');        	
	        	var pageLength = 15;
	        	initailPageNumber(pageBean.totalPage,pageBean.currentPage,pageLength);        
			});
	
        },
        error: function () {
        	console.log("error");
        }  
    });
}
